<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('代码生成说明')" />
	<link th:href="@{/css/blue.css}" rel="stylesheet"/>
	<link th:href="@{/css/nt-code.css}" rel="stylesheet"/>
    <link th:href="@{/css/update.css}" rel="stylesheet"/>
</head>
<body>
<div class="theme-default-content content__default"><h1 id="代码生成说明"><a href="#代码生成说明" aria-hidden="true" class="header-anchor">#</a> 代码生成说明</h1>
    <h2 id="代码生成"><a href="#代码生成" aria-hidden="true" class="header-anchor">#</a> 代码生成</h2> <p>大部分项目里其实有很多代码都是重复的，几乎每个基础模块的代码都有增删改查的功能，而这些功能都是大同小异，
    如果这些功能都要自己去写，将会大大浪费我们的精力降低效率。所以这种重复性的代码可以使用代码生成。</p> <div class="tip custom-block"><p class="custom-block-title">提示</p> <p>关于代码生成使用流程</p></div> <p>1、修改代码生成配置<br>
    单应用编辑<code>resources目录下的application.yml</code><br>
    多模块编辑<code>netintech-generator</code>中的<code>resources</code>目录下的<code>generator.yml</code><br> <code>author</code>:          # 开发者姓名，生成到类注释上<br> <code>packageName</code>:     # 默认生成包路径<br> <code>autoRemovePre</code>:   # 是否自动去除表前缀<br> <code>tablePrefix</code>:     # 表前缀</p> <p>2、新建数据库表结构（单表）</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">drop</span> <span class="token keyword">table</span> <span class="token keyword">if</span> <span class="token keyword">exists</span> sys_student<span class="token punctuation">;</span>
<span class="token keyword">create</span> <span class="token keyword">table</span> sys_student <span class="token punctuation">(</span>
  student_id           <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span>         <span class="token keyword">auto_increment</span>    <span class="token keyword">comment</span> <span class="token string">'编号'</span><span class="token punctuation">,</span>
  student_name         <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span>     <span class="token keyword">default</span> <span class="token string">''</span>        <span class="token keyword">comment</span> <span class="token string">'学生名称'</span><span class="token punctuation">,</span>
  student_age          <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span>          <span class="token keyword">default</span> <span class="token boolean">null</span>      <span class="token keyword">comment</span> <span class="token string">'年龄'</span><span class="token punctuation">,</span>
  student_sex          <span class="token keyword">char</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>         <span class="token keyword">default</span> <span class="token string">'0'</span>       <span class="token keyword">comment</span> <span class="token string">'性别（0男 1女 2未知）'</span><span class="token punctuation">,</span>
  student_status       <span class="token keyword">char</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>         <span class="token keyword">default</span> <span class="token string">'0'</span>       <span class="token keyword">comment</span> <span class="token string">'状态（0正常 1停用）'</span><span class="token punctuation">,</span>
  student_birthday     <span class="token keyword">datetime</span>                          <span class="token keyword">comment</span> <span class="token string">'生日'</span><span class="token punctuation">,</span>
  remark               <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">500</span><span class="token punctuation">)</span>    <span class="token keyword">default</span> <span class="token boolean">null</span>      <span class="token keyword">comment</span> <span class="token string">'备注'</span><span class="token punctuation">,</span>
  <span class="token keyword">primary</span> <span class="token keyword">key</span> <span class="token punctuation">(</span>student_id<span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">engine</span><span class="token operator">=</span><span class="token keyword">innodb</span> <span class="token keyword">auto_increment</span><span class="token operator">=</span><span class="token number">1</span> <span class="token keyword">comment</span> <span class="token operator">=</span> <span class="token string">'学生信息表'</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>2、新建数据库表结构（树表）</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">drop</span> <span class="token keyword">table</span> <span class="token keyword">if</span> <span class="token keyword">exists</span> sys_product<span class="token punctuation">;</span>
<span class="token keyword">create</span> <span class="token keyword">table</span> sys_product <span class="token punctuation">(</span>
  product_id        <span class="token keyword">bigint</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span>      <span class="token operator">not</span> <span class="token boolean">null</span> <span class="token keyword">auto_increment</span>    <span class="token keyword">comment</span> <span class="token string">'产品id'</span><span class="token punctuation">,</span>
  parent_id         <span class="token keyword">bigint</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span>      <span class="token keyword">default</span> <span class="token number">0</span>                  <span class="token keyword">comment</span> <span class="token string">'父产品id'</span><span class="token punctuation">,</span>
  product_name      <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span>     <span class="token keyword">default</span> <span class="token string">''</span>                 <span class="token keyword">comment</span> <span class="token string">'产品名称'</span><span class="token punctuation">,</span>
  order_num         <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span>          <span class="token keyword">default</span> <span class="token number">0</span>                  <span class="token keyword">comment</span> <span class="token string">'显示顺序'</span><span class="token punctuation">,</span>
  <span class="token keyword">status</span>            <span class="token keyword">char</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>         <span class="token keyword">default</span> <span class="token string">'0'</span>                <span class="token keyword">comment</span> <span class="token string">'产品状态（0正常 1停用）'</span><span class="token punctuation">,</span>
  <span class="token keyword">primary</span> <span class="token keyword">key</span> <span class="token punctuation">(</span>product_id<span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">engine</span><span class="token operator">=</span><span class="token keyword">innodb</span> <span class="token keyword">auto_increment</span><span class="token operator">=</span><span class="token number">1</span> <span class="token keyword">comment</span> <span class="token operator">=</span> <span class="token string">'产品表'</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p>3、登录系统（系统工具 -&gt; 代码生成 -&gt; 导入对应表）</p> <p>4、代码生成列表中找到需要表（可预览、修改、删除生成配置）</p> <p>5、点击生成代码会得到一个nt.zip  执行<code>sql</code>文件，按照包内目录结构复制到自己的项目中即可</p></div>
</body>
</html>